home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 12 / Game / GameMaterial.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  1.7 KB  |  46 lines

  1. //-----------------------------------------------------------------------------
  2. // GameMaterial.h implementation.
  3. // Refer to the GameMaterial.h interface for more details.
  4. //
  5. // Programming a Multiplayer First Person Shooter in DirectX
  6. // Copyright (c) 2004 Vaughan Young
  7. //-----------------------------------------------------------------------------
  8. #include "Main.h"
  9.  
  10. //-----------------------------------------------------------------------------
  11. // The game material class constructor.
  12. //-----------------------------------------------------------------------------
  13. GameMaterial::GameMaterial( char *name, char *path ) : Material( name, path )
  14. {
  15.     // Load the script for this material.
  16.     Script *script = new Script( name, path );
  17.  
  18.     // Store the step sounds.
  19.     m_stepSounds = new LinkedList< Sound >;
  20.     char stepSound[16] = { "step_sound0" };
  21.     while( script->GetStringData( stepSound ) != NULL )
  22.     {
  23.         m_stepSounds->Add( new Sound( script->GetStringData( stepSound ) ) );
  24.         sprintf( stepSound, "step_sound%d", m_stepSounds->GetTotalElements() );
  25.     }
  26.  
  27.     // Destory the material's script.
  28.     SAFE_DELETE( script );
  29. }
  30.  
  31. //-----------------------------------------------------------------------------
  32. // The game material class destructor.
  33. //-----------------------------------------------------------------------------
  34. GameMaterial::~GameMaterial()
  35. {
  36.     // Destroy the step sounds list.
  37.     SAFE_DELETE( m_stepSounds );
  38. }
  39.  
  40. //-----------------------------------------------------------------------------
  41. // Returns a random step sound from the list of step sounds.
  42. //-----------------------------------------------------------------------------
  43. Sound *GameMaterial::GetStepSound()
  44. {
  45.     return m_stepSounds->GetRandom();
  46. }